package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.adapter.AllLinkAdapter;
import com.sanpu.kxe.business.main.bean.HomeCenterOutput;
import com.sanpu.kxe.business.main.contract.AllApplicationContract;
import com.sanpu.kxe.business.main.presenter.AllApplicationPresenter;

import java.util.List;

import butterknife.Bind;

/**
 * Description：所有应用
 * Created by 薛勇军 on 2018/8/6.
 */
@Route(path = "/main/AllApplication")
public class AllApplicationActivity extends BaseTitleActivity implements AllApplicationContract.View {

    @Bind(R.id.grid_view)
    GridView vGridView;
    @Bind(R.id.emptyView)
    View emptyView;

    private AllLinkAdapter mAllLinkAdapter;

    private AllApplicationContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_al_link;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("全部应用");
        mAllLinkAdapter = new AllLinkAdapter(mContext);
        vGridView.setAdapter(mAllLinkAdapter);

        mPresenter = new AllApplicationPresenter(this);
        mPresenter.findHomeCenterMore();
    }

    @Override
    protected void setListener() {
        super.setListener();
        vGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mPresenter.onItemClick(((AllLinkAdapter) parent.getAdapter()).getItem(position));
            }
        });
    }

    @Override
    public void showDataView(List<HomeCenterOutput> centerOutputs) {
        if (centerOutputs != null && centerOutputs.size() > 0) {
            vGridView.setVisibility(View.VISIBLE);
            emptyView.setVisibility(View.GONE);
            mAllLinkAdapter.setNotifyData(centerOutputs);
        } else {
            vGridView.setVisibility(View.GONE);
            emptyView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(AllApplicationContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
